import localStorage from '@/utils/localStorage'
const strs = localStorage.getItem('logs')

/* 日志格式
{
  "createTime":"",
  "user":"",
  "action":"",
  "path":"",
  "content":"",
}
*/

var logs = []
if (strs) logs = JSON.parse(strs)

const state = {
  logs: logs,
}

const mutations = {
  logWrite: (state, item) => {
    while (state.logs.length >= 10) {
      state.logs.shift()
    }
    state.logs.push(item)
    localStorage.setItem('logs', JSON.stringify(state.logs))
  },
}

const actions = {
  logWrite({ commit }, item) {
    commit('logWrite', item)
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
